package cate.game.play.proce.turn;

import cate.game.play.fighter.Fighter;
import cate.game.play.proce.round.RoundCtx;
import cate.game.play.skill.Skill;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass(value = "追加行动轮次", detail = "在一个round中追加turn")
public class AppendTurn {

	@NoteField("追加行动者")
	public Fighter actor;

	@NoteField("追加的技能")
	public Skill skill;

	@NoteField("追加turn handler")
	public AppendTurnHandler handler;

	public AppendTurn(Fighter actor, Skill skill) {
		this.actor = actor;
		this.skill = skill;
	}

	public AppendTurn(Fighter actor, Skill skill, AppendTurnHandler handler) {
		this.actor = actor;
		this.skill = skill;
		this.handler = handler;
	}

	public void beforeAppendTurn(RoundCtx round) {
		if (handler != null) {
			handler.beforeAppendTurn(round, this);
		}
	}

	public void onAppendTurnFail(RoundCtx round) {
		if (skill != null) {
			skill.reset();
		}
		if (handler != null) {
			handler.onAppendTurnFail(round, this);
		}
	}

	/**
	 * 当前这个追加行动是否失效
	 * @return
	 */
	public boolean inValid(RoundCtx round) {
		if (!actor.allowUseSkill(skill)) {
			return true;
		}
		if (!actor.buff.allowAppendMove(skill)) {
			return true;
		}
		if (handler != null && handler.inValid(round, this)) {
			return true;
		}
		return false;
	}
}
